/**
 * @param {number} left
 * @param {number} right
 * @return {number[]}
*/
var selfDividingNumbers = function(left, right) {
  let result = [];

  function process(num) {
    let str = num.toString().split("");
    for(let i = 0; i < str.length; i++) {
      if(num % parseInt(str[i]) != 0) return ;
    }
    result.push(num);
  }

  for(let i = left; i <= right; i++) {
    if(i < 10) {
      result.push(i);
    } else {
      process(i);
    }
  }
  return result;
};
let left = 1, right = 22;
console.log(selfDividingNumbers(left, right));
left = 47, right = 85;
console.log(selfDividingNumbers(left, right));
